<template>
  <div>
    <FindMusicNav />
    <div id="one-box">
      <div class="left-tabs">
        <RadioBox
          :options="allOptions"
          :title="allTitle"
          :radioOptions="radioOptions"
          @selectChange="selectChange"
        />
        <RadioBox
          :options="chinaOptions"
          :title="chinaTitle"
          :radioOptions="radioOptions"
          @selectChange="selectChange"
        />
        <RadioBox
          :options="americaOptions"
          :title="americaTitle"
          :radioOptions="radioOptions"
          @selectChange="selectChange"
        />
        <RadioBox
          :options="japanOptions"
          :title="japanTitle"
          :radioOptions="radioOptions"
          @selectChange="selectChange"
        />
        <RadioBox
          :options="koreaOptions"
          :title="koreaTitle"
          :radioOptions="radioOptions"
          @selectChange="selectChange"
        />
        <RadioBox
          :options="outherOptions"
          :title="outherTitle"
          :radioOptions="radioOptions"
          @selectChange="selectChange"
        />
      </div>
      <div class="right-singer">
        <h3 class="h3-title">
          <span>{{ selectTitle }}</span>
          <div class="right-button">
            <span>当前{{page}}页</span>
            <button @click="pageing(0)" class="white-button">首页</button>
            <button @click="pageing(1)" :disabled="page == 1" :class="{'disbtn':page==1?true:false}" class="white-button">上一页</button>
            <button @click="pageing(2)" :disabled="!next" class="white-button">下一页</button>
          </div>
        </h3>
        <div class="list">
          <div v-for="item in artists" :key="item.id" class="list-item">
            <div class="img">
              <img @click="screenMusic(item)" :src="item.picUrl" :title="item.name+'的音乐'" alt="" />
            </div>
            <div class="details">
              <div @click="screenMusic(item)" class="name" :title="item.name+'的音乐'">{{ item.name }}</div>
              <div @click="screenHomePage(item)" class="iconfont" :title="item.name+'的个人主页'">&#xe7ad;</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import FindMusicNav from "@/components/findMusicNav";
import RadioBox from "./RadioBox";
import { artistList } from "@/api";
export default {
  name: "singer",
  components: {
    FindMusicNav,
    RadioBox,
  },
  data() {
    return {
      next:false,
      artists: [],
      page: 1,
      total: 100,
      selectTitle: "全部",
      radioOptions: {
        select: '{"name":"全部","area":"-1","type":"-1"}',
      },
      allTitle: "全部",
      allOptions: [
        { name: "全部", area: "-1", type: "-1" },
        { name: "男歌手", area: "-1", type: "1" },
        { name: "女歌手", area: "-1", type: "2" },
        { name: "乐队", area: "-1", type: "3" },
      ],
      chinaTitle: "华语",
      chinaOptions: [
        { name: "华语", area: "-7", type: "-1" },
        { name: "华语男歌手", area: "7", type: "1" },
        { name: "华语女歌手", area: "7", type: "2" },
        { name: "华语乐队", area: "7", type: "3" },
      ],
      americaTitle: "欧美",
      americaOptions: [
        { name: "欧美", area: "96", type: "-1" },
        { name: "欧美男歌手", area: "96", type: "1" },
        { name: "欧美女歌手", area: "96", type: "2" },
        { name: "欧美乐队", area: "96", type: "3" },
      ],
      japanTitle: "日本",
      japanOptions: [
        { name: "日本", area: "8", type: "-1" },
        { name: "日本男歌手", area: "8", type: "1" },
        { name: "日本女歌手", area: "8", type: "2" },
        { name: "日本乐队", area: "8", type: "3" },
      ],
      koreaTitle: "韩国",
      koreaOptions: [
        { name: "韩国", area: "16", type: "-1" },
        { name: "韩国男歌手", area: "16", type: "1" },
        { name: "韩国女歌手", area: "16", type: "2" },
        { name: "韩国乐队", area: "16", type: "3" },
      ],
      outherTitle: "其他",
      outherOptions: [
        { name: "其他", area: "0", type: "-1" },
        { name: "其他男歌手", area: "0", type: "1" },
        { name: "其他女歌手", area: "0", type: "2" },
        { name: "其他乐队", area: "0", type: "3" },
      ],
    };
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      this.getArtistList();
    },
    getArtistList() {
      let radioOptions = JSON.parse(this.radioOptions.select);
      artistList({
        ...radioOptions,
        limit: 30,
        offset: (this.page - 1) * 30,
      }).then((data) => {
        this.artists = data.artists;
        this.next = data.more
      });
    },
    selectChange(val) {
      this.radioOptions.select = val;
      this.page = 1;
      this.selectTitle = JSON.parse(val).name;
      this.getArtistList()
    },
    pageing(val) {
      if (val == 0) {
        this.page = 1
        this.getArtistList()
      } else if (val == 1) {
        this.page--
        this.getArtistList()
      } else if (val == 2) {
        this.page++
        this.getArtistList()
      }
    },
    screenMusic(val){
      const {accountId} = val
      if(!accountId){
        this.$Notification("此用户暂无信息")
        return
      }
      this.$router.push({
        // name:"singerDetails",
        name:"userpage",
        query:{id:accountId}
      })
    },
    screenHomePage(val){
      const {accountId} = val
      if(!accountId){
        this.$Notification("此用户暂无信息")
        return
      }
      this.$router.push({
        name:"userpage",
        query:{id:accountId}
      })
    }
  },
};
</script>

<style lang="scss" scoped>
.disbtn{
  cursor: no-drop!important;
}
#one-box {
  margin-top: 0;
  display: flex;
  padding: 0;
  .left-tabs {
    box-sizing: border-box;
    width: 180px;
    border-right: 1px solid rgb(211, 211, 211);
    background-color: rgb(249, 249, 249);
    padding: 0px 10px;
    padding-bottom: 40px;
  }
  .right-singer {
    .list {
      display: flex;
      flex-wrap: wrap;
      .list-item {
        margin: 15px;
        width: 117px;
        .img {
          width: 100%;
          height: 117px;
          cursor: pointer;
          img {
            width: 100%;
            height: 100%;
          }
        }
        .details {
          margin-top: 10px;
          display: flex;
          justify-content: space-between;
          .name {
            width: 90px;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            font-size: 12px;
            color: #000;
            cursor: pointer;
            &:hover {
              text-decoration: underline;
            }
          }
          .iconfont {
            cursor: pointer;
            color: rgb(217, 25, 33);
          }
        }
      }
    }
    ::v-deep ._v-container {
      position: static;
    }
    box-sizing: border-box;
    padding: 40px;
    flex: 1;
    .footer-size {
      text-align: center;
      margin-top: 25px;
      ::v-deep .el-pagination__sizes {
        display: none;
      }

      ::v-deep li {
        font-weight: 400 !important;
        &:hover {
          border-color: rgb(102, 102, 102) !important;
          color: rgb(51, 51, 51) !important;
        }
        border-radius: 2px;
        border: 1px solid rgb(204, 204, 204) !important;
        background-color: #fff !important;
      }
      ::v-deep li.active {
        background-color: #a2161b !important;
        border-color: rgb(162, 22, 27);
        &:hover {
          color: #fff !important;
          border-color: rgb(102, 102, 102) !important;
        }
      }
    }
  }
}
.h3-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 24px;
  padding-bottom: 8px;
  color: rgb(51, 51, 51);
  font-family: "Microsoft Yahei", Arial, Helvetica, sans-serif;
  border-bottom: 2px solid #c20c0c;
  .right-button {
    font-size: 12px;
    button {
      margin: 0 4px;
    }
    .white-button {
      cursor: pointer;
      &:hover {
        background-image: linear-gradient(#ccc, #fff);
      }
    }
  }
}
</style>